﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Data;
using System.Web;
using MySql.Data.MySqlClient;

/// <summary>
/// Summary description for StockAnalysis
/// </summary>
public class StockAnalysis
{
  private const string SP_main_figures = "Main_figures";
  private const string SP_profitability_solvency = "Profitability_solvency";
  private const string SP_earning_growth = "Earning_growth";
  private const string SP_cashflow_liguidity = "Cashflow_liquidity";
  private const string SP_stock_keyfigures = "Stock_keyfigures";
  DatabaseManager db;
  DataTable dataTable;

  public StockAnalysis()
  {
    db = new DatabaseManager();
  }

  public DataTable GetMainFiguresTable(string id)
  {
    return LoadDataTable(id, SP_main_figures);
  }

  public DataTable GetProfitabilitySolvencyTable(string id)
  {
    return LoadDataTable(id, SP_profitability_solvency);
  }

  public DataTable GetStockKeyfiguresTable(string id)
  {
    return LoadDataTable(id, SP_stock_keyfigures);
  }

  public DataTable GetEarningGrowthTable(string id)
  {
    return LoadDataTable(id, SP_earning_growth);
  }

  public DataTable GetCashflowLiquidityTable(string id)
  {
    return LoadDataTable(id, SP_cashflow_liguidity);
  }

  //# # # # # Private methods # # # # #
  private DataTable LoadDataTable(string id, string storedProcedure)
  {
    dataTable = new DataTable();
    db.AddParameter("@id", id);
    dataTable.Load(db.ExecuteStoredProcedure(storedProcedure));
    return dataTable;
  }
}